#include <iostream>
#include <pthread.h>
using namespace std;
class Mutex
{
public:
    Mutex(pthread_mutex_t *pm)
        : _pm(pm)
    {
    }
    void lock()
    {
        pthread_mutex_lock(_pm);
    }
    void unlock()
    {
        pthread_mutex_unlock(_pm);
    }

private:
    pthread_mutex_t *_pm;
};

class MutexGuard
{
public:
    MutexGuard(pthread_mutex_t *pm)
        : _m(pm)
    {
        _m.lock();
    }
    ~MutexGuard()
    {
        _m.unlock();
    }

private:
    Mutex _m;
};